﻿using System.Collections.Specialized;
using System.Xml;

namespace SVTTranslateTextEngine.Entities
{
    /// <summary>
    /// This class handle the support language setting accress .
    /// </summary>
    public class SupportLanguageInfo
    {
        protected string vendor_name;

        /// <summary>
        /// Create the object function
        /// </summary>
        /// <param name="szVendorName">Vendor Name Which the Translate Engine Supported</param>
        public SupportLanguageInfo(string szVendorName)
        {
            vendor_name = szVendorName;
            if (LanguageInfo == null) LanguageInfo = new NameValueCollection();
        }

        /// <summary>
        /// Build the SupportLanguageInfo object by xml node context. 
        /// </summary>
        /// <param name="supportLangNode">XML node which can build the SupportLanguageInfo object </param>
        public SupportLanguageInfo(XmlNode supportLangNode)
        {
            if (supportLangNode != null && supportLangNode.ChildNodes.Count > 0 && supportLangNode.ChildNodes[0].ChildNodes.Count > 0
                && supportLangNode.Attributes != null && supportLangNode.Attributes["name"] != null)
            {
                vendor_name = supportLangNode.Attributes["name"].Value;
                foreach (XmlNode langNode in supportLangNode.ChildNodes[0].ChildNodes)
                {
                    if (langNode.Attributes != null && langNode.Attributes["code"] != null &&
                        langNode.Attributes["en_name"] != null)
                    {
                        var langCode = langNode.Attributes["code"].Value;
                        var langEName = langNode.Attributes["en_name"].Value;
                        LanguageInfo.Add(langCode, langEName);
                    }

                }
            }
        }

        /// <summary>
        /// the vendor' name of the translate engine api supporter ;
        /// </summary>
        public string VendorName
        {
            get { return vendor_name; }
        }

        /// <summary>
        /// the support language information .
        /// Key is the language's code 
        /// Value is the language's English name .
        /// </summary>
        public NameValueCollection LanguageInfo { get; set; }
    }
}